home *** CD-ROM | disk | FTP | other *** search
/ Aminet 40 / Aminet 40 (2000)(Schatztruhe)[!][Dec 2000].iso / Aminet / util / cdity / ModeProSrc.lha / Daemon / MPLockPubPatch.c < prev    next >
C/C++ Source or Header  |  1999-01-01  |  5KB  |  179 lines

  1. #define DEBUG
  2. #define ADD_DEBUG_CODE
  3. #include <debug.h>
  4. #include "patchdata.h"
  5.  
  6. #include "MP.h"
  7. #include <extras/macros/exec.h>
  8.  
  9. struct SignalSemaphore LockPubSem;
  10.  
  11. extern struct Process  *MPTask;
  12. extern BYTE   PublicSignal;
  13. extern struct MPSem *MPSem;
  14. extern UBYTE   ModePro[];
  15.  
  16. extern struct Screen * __asm (*OldLockPubScreen)(register __a0 UBYTE *Name,
  17.                                                  register __a6 struct Library *);
  18. extern void __asm (*OldUnlockPubScreen)(register __a0 UBYTE *Name,
  19.                                         register __a1 struct Screen *,
  20.                                         register __a6 struct Library *);
  21.  
  22.  
  23. struct Screen * __saveds __asm NewLockPubScreen(register __a0 UBYTE *Name,
  24.                                                 register __a6 struct IntuitionBase *IBase)
  25. {
  26.   struct OpenNode *on;
  27.   struct Screen *scr, *ps;
  28.   struct DefaultNode *dnode;
  29.   LONG button;
  30.   char tnamebuffer[52];
  31.   char *tname;
  32.   ULONG stack1=0xc0de0020;
  33.   
  34.   DoNothing(&stack1);
  35.   
  36.   tname=SetupTaskName(tnamebuffer,", LPS",50);
  37.  
  38. DEBUG_CODE(DKP("LockPubScreen(%s)\n",Name););
  39.  
  40.   ps=0;
  41.  
  42.   if(scr=OldLockPubScreen(Name,(struct Library *)IntuitionBase))
  43.   {
  44. DEBUG_CODE(DKP("  RV=0x%08lx (Existing screen)\n",scr););
  45.  
  46.     SetTaskName(tname);
  47.     
  48.     return(scr);
  49.   }
  50.   else
  51.   {
  52. DEBUG_CODE(DKP("  LPS Initial lock failed\n"););
  53.     if(strcmp("Workbench",Name)) // Can't f with Workbench! //4.53 @1 rewired //                       (4.62.6)
  54.     {
  55.       ObtainSemaphore(&LockPubSem);               //4.53 @11      // 4.54 @1 (comment out)
  56.       if(scr=OldLockPubScreen(Name,(struct Library *)IntuitionBase))
  57.       {
  58. DEBUG_CODE
  59.         (
  60.           DKP("  Secondary lock attempt succeeded!\n");
  61.           DKP("  RV=0x%08lx\n",scr);
  62.         );
  63.   
  64.         SetTaskName(tname);
  65.   
  66.         ReleaseSemaphore(&LockPubSem);      //4.53 @11    
  67.         
  68.         return(scr);
  69.       }
  70.       else    
  71.       {
  72. DEBUG_CODE(DKP("  LPS Secondary lock failed\n"););
  73.         ObtainSemaphoreShared(&MPSem->ListSem);   //4.53 @11 (comment out) // 4.54 @1 (UNcomment out)
  74.         ObtainSemaphore(&MPSem->NodeSem);         //4.53 @11 (comment out) // 4.54 @1 (UNcomment out)
  75.         
  76.         if(dnode=FindDNode(&MPSem->PromotionList[PL_PUBLICSCREENS],Name))
  77.         {
  78.           if(dnode->Flags & DNF_NEVER_PROMOTE)
  79.             dnode=0;
  80.           else
  81.             dnode=DupDNode(dnode);
  82.   
  83.           ReleaseSemaphore(&MPSem->NodeSem);    
  84.         }
  85.         else
  86.         {
  87.           ReleaseSemaphore(&MPSem->NodeSem);    
  88.           if(MPSem->CatchPubScreens)
  89.           {
  90.             if(button=EZReq(0,0,ModePro,GetString(MSG_NEW_PUBSCREEN),GetString(MSG_NEW_PUBSCREEN_BUTTONS),(ULONG)Name))
  91.             {
  92.               if(dnode=AllocDefaultNode(Name))
  93.               {
  94.                 dnode->Type=PL_PUBLICSCREENS;
  95.                 dnode->ModeSelect=2;
  96.                 CloneWB(dnode);
  97.                 dnode=ForceEdit(dnode);
  98.               }   
  99.             }
  100.           }
  101.         }
  102.         
  103.         
  104.         ReleaseSemaphore(&MPSem->ListSem);
  105.         
  106.         ps=0;
  107.         
  108.         if(dnode)
  109.         {
  110.  
  111. DEBUG_CODE(DKP("  Creating new pubscreen %s\n",Name););
  112.           
  113.           FreeVec(dnode->PubName);
  114.           dnode->PubName=Name;
  115.           dnode->PubOptions=1;
  116.       
  117.           if(scr=OpenScreenTags(0, SA_Title                 ,Name,
  118.                                    SA_ModeProNode           ,dnode,
  119.                                    TAG_DONE))
  120.           {
  121.             if(ps=OldLockPubScreen(Name,(struct Library *)IntuitionBase))
  122.             {
  123.               //4.53 @8 now clears ON_OPEN flag
  124.               ObtainSemaphore(&MPSem->OpenListSem);
  125.               if(on=FindOpenNode(ps))
  126.               {
  127.                 // clear the open flag so MP can close the screen
  128.                 on->Flags&=(~ON_OPEN);
  129.               }
  130.               ReleaseSemaphore(&MPSem->OpenListSem);
  131.             }
  132.           }
  133.           
  134.           dnode->PubName=0;
  135.           dnode->PubOptions=0;
  136.           
  137.           FreeDNode(dnode);
  138.         }      
  139.         ReleaseSemaphore(&LockPubSem);
  140.       } // end if(!"workbench")
  141.     }
  142.   }
  143.  
  144. DEBUG_CODE(DKP("  RV=0x%08lx\n",ps););
  145.  
  146.   SetTaskName(tname);
  147.   
  148.   return(ps);
  149. }                          
  150.  
  151.  
  152.  
  153. // 4.53 @9 New patch
  154. void __saveds __asm NewUnlockPubScreen(register __a0 UBYTE *Name, 
  155.                                        register __a1 struct Screen *Scr,
  156.                                        register __a6 struct Library *IBase)
  157. {
  158.   //BOOL signal=0;
  159.   //struct List *plist;
  160.   //struct PubScreenNode *psn;
  161.   //struct OpenNode *on;
  162.   char tnamebuffer[52];
  163.   char *tname;
  164.   ULONG stack1=0xc0de0021;
  165.  
  166.   DoNothing(&stack1);
  167.   
  168.   tname=SetupTaskName(tnamebuffer,", ULPS",50);
  169.  
  170. DEBUG_CODE(DKP("UnLockPubScreen(%s,0x%08lx)\n",Name,Scr););
  171.  
  172.   OldUnlockPubScreen(Name,Scr,IBase);
  173.  
  174.   // signal MP, birdie kludge
  175.   Signal((struct Task *)MPTask,1<<PublicSignal);
  176.   
  177.   SetTaskName(tname);
  178. }
  179.